<template>
	<view class="main">
		<!-- 数据为空 -->
		<view class="noSearch" v-if="inspectionRecords.length==0">
			<div style="height: 100px;"></div>
			<view class="a" v-show="!isOk">
				<div style="height: 100px;"></div>
				<u-loading-icon mode="circle" size="50px"></u-loading-icon>
			</view>
			<view class="b" v-show="isOk">
				<u-empty mode="search" text="暂无数据"></u-empty>
			</view>
		</view>
		<!-- 巡检记录 -->
		<div style="padding-top: 2px;background-color: #FFF;"><u-line></u-line></div>
		<div style="height: 5px;"></div>
		<view class="content" :style="getHeight()">
			<u-list :lowerThreshold="10" @scrolltolower="scrolltolowerX()" :style="getHeight()">
				<u-list-item v-for="(item,index) in inspectionRecords" :key="index" 
					style="background-color: #FFFFFF;margin: 0px 5px 10px 5px;border-radius: 8px;padding: 16px 16px;box-shadow: 0px 5px 10px rgba(0, 0, 0, 0.05);">
					<view class="cc" style="display: flex;align-items: center;">
						<view class="left">
							<u--image radius="5" :src="item.xjfj==null?'/static/icons/no_img.png':item.xjfj" 
								:width="getWidthImg()" :height="getHeightImg()">
							</u--image>
						</view>
						<view class="right" style="margin-left: 10px;">
							<!-- <view class="top" :style="getStyle()">
								<view class="a" style="display: flex;">
									<u-icon size="16" name="clock" style="margin-right: 5px;"></u-icon>
									<u-text :text="item.kssj!=null?item.kssj:''" style="white-space: nowrap;"></u-text>
								</view>
								<view class="b" style="display: flex;">
									<u-icon size="18" name="account" style="margin-right: 5px;"></u-icon>
									<u-text :text="item.xjrxm"></u-text>
								</view>
							</view>
							<view class="bottom" :style="getTop()">
								<u-text blod :text="item.xjms"></u-text>
							</view> -->
							<view class="a" style="display: flex;justify-content: space-between;">
								<view class="aa" style="display: flex;">
									<u-icon size="18" name="account" style="margin-right: 5px;margin-top: 2px;"></u-icon>
									<u-text :text="item.xjrxm"></u-text>
								</view>
								<view class="bb">
									<u-text text="正常" type="success" v-show="item.sfyc==0"></u-text>
									<u-text text="异常" type="error" v-show="item.sfyc==1"></u-text>
								</view>
							</view>
							<view class="b" style="display: flex;align-items: flex-start;">
								<u-icon size="16" name="clock" style="margin-right: 6px;margin-top: 3px;margin-left: 1px;"></u-icon>
								<view class="br" style="display: flex;flex-wrap: wrap">
									<u-text :text="getText(item.kssj)" style="white-space: nowrap;"></u-text>
									<u-text text="~" style="margin-left: 5px;"></u-text>
									<u-text :text="getText(item.jssj)" style="white-space: nowrap;"></u-text>
								</view>
							</view>
							<view class="d" style="display: flex;">
								<u-icon size="18" name="file-text" style="margin-right: 5px;margin-top: 2px;"></u-icon>
								<u-text blod :text="item.xjms"></u-text>
							</view>
						</view>
					</view>
				</u-list-item>
			</u-list>
		</view>
<!-- 		<u-list @scrolltolower="scrolltolower">
			<u-list-item v-for="(item, index) in inspectionRecords" :key="index"
				style="background-color: white;padding-bottom:3px">
				<u-row class="list-item">
					<u-col span="4">
						<u--image style="margin-left: 10px;" radius="5"
							:src="item.src==null?'/static/icons/no_img.png':item.src" width="120px"
							height="100px"></u--image>
					</u-col>
					<u-col span="8" style="margin-left: 20px; height: 70%;">
						<u-row>
							<u-col span="1">
								<u-icon size="18" name="clock"></u-icon>
							</u-col>
							<u-col span="5">
								<u-text :text="item.kssj!=null?item.kssj:''">
								</u-text>
							</u-col>
							<u-col span="1">
								<u-icon size="18" name="account"></u-icon>
							</u-col>
							<u-col span="3">
								<u-text :text="item.xjrxm">
								</u-text>
							</u-col>
						</u-row>
						<u-row v-if="item.jssj!=null">
							<u-col span="4">
								<u-text bold text="结束时间："></u-text>
							</u-col>
							<u-col span="8">
								<u-text :text="item.jssj">
								</u-text>
							</u-col>
						</u-row>
						<u-row style="margin-top: 20px; height: 50px;">
							<u-col span="12">
								<u-text blod :text="item.xjms">
								</u-text>
							</u-col>
						</u-row>
					</u-col>
				</u-row>
			</u-list-item>
		</u-list>
	 -->
	</view>
</template>

<script>

import croods from '@/common/croods-1.3.3.js';     window.croods = croods;  window.hydra =  require('../../../../common/wst_hydra-1.0.0.js');


	import coordtransform from 'coordtransform';
	import {
		getRecord
	} from '@/common/api.js';
	export default {
		props: ['selectId'],
		data() {
			return {
				inspectionRecords: [],
				pageNum: 1,
				pageSize: 20,
				total: 0,
				isOver:false,
				isOk:false,
			}
		},
		async mounted() {
			this.isOk = false
			let records = await getRecord({
				id: this.selectId,
				pageNum: this.pageNum,
				pageSize: this.pageSize
			})
			this.total = records.total;
			this.isOver = records.nextPage==0;
			this.inspectionRecords = records.list.map(it=>{
                it.kssj = it.kssj.split(" ")[0]
                return it
            });
			this.isOk = true
			/* console.log(this.inspectionRecords); */
		},
		methods: {
			/* async scrolltolower() {
				let that = this;
				if (that.inspectionRecords.length < total) {
					that.pageNum += 1;
					try {
						const res = await getRecord({
							id: that.selectId,
							pageNum: that.pageNum,
							pageSize: that.pageSize
						});
						that.inspectionRecords = that.inspectionRecords.concat(records.list);
					} catch (e) {}
				} else {
					return;
				}
			}, */
			async scrolltolowerX(){
				let that = this
				if(that.isOver){
					return
				}else{
					that.pageNum += 1
					try {
						const res = await getRecord({
							id: that.selectId,
							pageNum: that.pageNum,
							pageSize: that.pageSize
						});
						that.inspectionRecords = that.inspectionRecords.concat(records.list);
					} catch (e) {}
				}
			},
			getHeight(){
				let a = uni.getSystemInfoSync().windowHeight - 78
				return{
					'height':a + 'px'
				}
			},
			getHeightImg(){
				let a = uni.getSystemInfoSync().windowWidth
				let temp = ''
				if(a<370){
					temp = a * 0.22
				}else{
					temp = a * 0.3
				}
				let bi = 3/4
				let b = bi * temp
				return b + 'px'
			},
			getWidthImg(){
				let a = uni.getSystemInfoSync().windowWidth
				let temp = ''
				if(a<370){
					temp = a * 0.22
				}else{
					temp = a * 0.3
				}
				return temp + 'px'
			},
			getTop(){
				let a = uni.getSystemInfoSync().windowWidth
				let temp = ''
				if(a<370){
					temp = a * 0.22
				}else{
					temp = a * 0.3
				}
				let bi = 3/4
				let x = bi * temp
				let b = x - 30
				return {
					'margin-top':b + 'px'
				}
			},
			getText(text){
				if(text==null || text.length==0 || text==undefined){
					return '暂无时间'
				}else{
					if(text.length<16){
						/* let temp = text.slice(0,10) + ' 00:00'
						return temp */
						return text
					}else{
						let temp = text.slice(0,16)
						return temp
					}
				}
			},
			getStyle(){
				let a = uni.getSystemInfoSync().windowWidth
				let temp = ''
				if(a<370){
					temp = a * 0.58
				}else{
					temp = a * 0.52
				}
				return{
					'display':'flex',
					'justify-content':'space-between',
					'width':temp + 'px'
				}
			}
		},
		onShow(){
			document.body.style.overflow = 'auto';
		}
	}
</script>

<style lang="scss">
	.list-item {
		height: 120px;
		margin: 3px;
		background-color: white;
		box-shadow: 0 1px 2px 0 rgba(0, 0, 0, .1);
		border-radius: 8px;
		border: 1px solid #ebeef5
	}
	.main{
		height: 100%;
		background-color: #FAFAFA;
	}
</style>